package databasetest;

import java.awt.EventQueue;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.text.DecimalFormat;

import javax.swing.JInternalFrame;
import javax.swing.JFrame;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.JTextField;
import javax.swing.JLabel;

public class Insert extends JInternalFrame {
	Connection conn;
	private JButton btnNewButton;
	private JTextField code;
	private JTextField ea;
	private JLabel lblNewLabel;
	private JLabel label;
	Select s;


	public Insert(Connection c) {
		super("Insert",true,true,true,false);
		setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
		setBounds(100, 100, 271, 102);
		
		this.conn=c;
		getContentPane().setLayout(null);
		getContentPane().add(getBtnNewButton());
		getContentPane().add(getCode());
		getContentPane().add(getEa());
		getContentPane().add(getLblNewLabel());
		getContentPane().add(getLabel());
		

	}
	public void setD(Select s){
		this.s=s;
	}

	private JButton getBtnNewButton() {
		if (btnNewButton == null) {
			btnNewButton = new JButton("입력");
			btnNewButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					
					try{
						String c= code.getText();
						int e= Integer.parseInt(ea.getText());
						
						String sql ="insert into ptbl(serial,code,ea) values(seq_no.nextval,?,?)";
						PreparedStatement pstmt=
								conn.prepareStatement(sql);
						pstmt.setString(1, c);
						pstmt.setInt(2, e);
						pstmt.executeUpdate();//입력,수정,삭제;
						
						//pstmt.executeQuery();//조회
						
						s.columnadd();
						
					}catch(Exception e){
						
					}
				}
			});
			btnNewButton.setBounds(174, 10, 69, 52);
		}
		return btnNewButton;
	}
	private JTextField getCode() {
		if (code == null) {
			code = new JTextField();
			code.setBounds(60, 10, 102, 23);
			code.setColumns(10);
		}
		return code;
	}
	
	private JTextField getEa() {
		if (ea == null) {
			ea = new JTextField();
			ea.setColumns(10);
			ea.setBounds(60, 39, 102, 23);
		}
		return ea;
	}
	private JLabel getLblNewLabel() {
		if (lblNewLabel == null) {
			lblNewLabel = new JLabel("코드");
			lblNewLabel.setBounds(12, 10, 41, 23);
		}
		return lblNewLabel;
	}
	private JLabel getLabel() {
		if (label == null) {
			label = new JLabel("수량");
			label.setBounds(12, 39, 41, 23);
		}
		return label;
	}
}
